package com.zcah.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class JredisConfig {

    @Autowired
    @Bean(value = "redisTemplate")
    public RedisTemplate getTemplate(@Qualifier("getFactory") JedisConnectionFactory factory) {
        RedisTemplate template = new RedisTemplate();
        template.setConnectionFactory(factory);
        template.setDefaultSerializer(new StringRedisSerializer());
        return template;
    }

    @Qualifier("getFactory")
    @Bean
    public JedisConnectionFactory getFactory() {
        JedisConnectionFactory f = new JedisConnectionFactory();
        f.setHostName("192.168.188.141");
        f.setDatabase(0);
        f.setPassword("Cnitsec%432");
        return f;
    }
}
